<include file="Public:header"/>
<link rel="stylesheet" href="__WEBPUBLIC__/Uploadify/uploadify.css" type="text/css" />
<!--主页面-->
<div id="main-content" class="content">
    <ul class="breadcrumb">
        <li><a href="/">首页</a></li>
        <li class="active"><a href="">Banner管理</a></li>
        <li class="active">添加Banner</li>
    </ul>

    <div class="page-header clearfix">
        <h3>添加Banner</h3>
        <ul class="nav nav-tabs">
            <li  class="">
                <a href="{:U('Banner/bannerList')}">Banner列表</a>
            </li>
            <li  class="active">
                <a href="javascript:;">添加相册</a>
            </li>
        </ul>
    </div>

    <div id="tabs-content" class="content-box-content">
        <div class="ul">
            <form action="{:U('Banner/addBanner')}" method="post" class="form-horizontal form" enctype="multipart/form-data">

                <div class="form-group">
                    <label class="col-sm-3 control-label"><em class="prompt-red">*</em>Banner图片：</label>
                    <div id="imgPreviewMore">

                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label"></label>
                    <div class="col-sm-9">
                        <input type="file" name="pic_upload" multiple/>
                        <span style="color: red">框选上传多张图片</span>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-3 col-sm-9">
                        <button type="submit" class="btn btn-default btn-primary make_sure">确认添加</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<include file="Public:footer"/>
<!--商家的头像和商家的展示图的上传-->
<script>

    function ajax1(){
        var filesize = this.files[0].size;
        if (filesize > 10000*1024) {
            alert("请上传大小在500k以下的图片");
            return false;
        }
        var files = this.files;
        var i = '';
        for(i=0;files.length;i++){
            var picname = files[i].name;
            var reader = new FileReader();
            reader.onload = function(e){
                var src = e.target.result;
                $.ajax({
                    type:"post",
                    url:"{:U('Banner/uploadPic')}",
                    data: {"pic":src,"pic_name":picname},
                    dataType : "json",
                    success : function(data){
                        var data = JSON.parse(data);
                        if(data['flag'] == "success"){
                            $("#imgPreviewMore").append("<div class='parents' style='float: left'><div class='one_more_del'>[-]</div>" +
                                    "<input type='hidden' value='"+data['data']['path']+"' name='pic[]'/>"+
                                    "<div><img src='"+'/'+data['data']['path']+"' style='width: 150px;'></div></div>");
                        }
                        bindClickMore();
                    }
                });
            }
            reader.readAsDataURL(files[i]);
        }
    }
    $("input[name='pic_upload']").on('change',ajax1);

    function bindClickMore() {
        $(".one_more_del").off("click");
        $(".one_more_del").click(function () {
            var url = "{:U('Banner/delPhoto')}";
            var file_path = $(this).next().val();
            $.post(url,{file_path:file_path},function(data){
                if(data == 1){
                    $(this).parent().remove();
                }else{
                    alert("删除失败！请重新尝试！");
                }
            }.bind(this))
        });
    }
    bindClickMore();

</script>
